package org.bigk.invoices.services;

import java.math.BigDecimal;

import org.bigk.invoices.model.InvoicePositionSummary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * This implementation of {@link RecalcTotalOfIPSService} rounds
 * {@link InvoicePositionSummary#getTotal()} with
 * {@link BigDecimal.ROUND_HALF_UP} mode.
 * 
 * @author 125914
 *
 */
@Service("recalcTotalOfIPSService")
@Transactional
public class RecalcTotalOfIPSServiceImplRound
		implements RecalcTotalOfIPSService {

	@Override
	public void recalculateTotal(InvoicePositionSummary ips) {
		
		BigDecimal total = ips.getTotal();
		if (total != null) {
			total = total.setScale(0, BigDecimal.ROUND_HALF_UP);
			ips.setTotal(total);
		}
		
	}
	
}
